<?php if($user->access!=0){ 
//Variable pour la gestion des pages
if( !isset($_GET['nbpage']) OR !  ctype_digit($_GET['nbpage']) OR ( ctype_digit($_GET['nbpage']) AND $_GET['nbpage']<=1 ) ){
	$page = 1;
}else{
	$page = mysql_escape_string($_GET['nbpage']);
}
$nbmesspage = 10;
$nbmess = PostMessage::getNbMessage();
$nbpage = ceil($nbmess/$nbmesspage);
$firstmess = ($page * $nbmesspage) -$nbmesspage;
//end of variables


	$word=mysql_query("Select ".DATABASE_TABLE_MESSAGE.".id,".DATABASE_TABLE_USER.".login as user,message,date
					from ".DATABASE_TABLE_MESSAGE." 
					LEFT JOIN ".DATABASE_TABLE_USER."
					ON ".DATABASE_TABLE_MESSAGE.".user = ".DATABASE_TABLE_USER.".id 
					ORDER BY `date` DESC LIMIT $firstmess,$nbmesspage;");

?>



<div id="page_message">

	<table style="width:80%">
	<caption>
		Messages <input type="button" value="Add message" onclick="affichage_popup('message','400','160')" /><br />
		<span class ="page">
			Pages [ <?php
			$i = 1;
			while ($i != $nbpage+1){
			?>
				<a <?php if($i==$page){print 'style="font-weight:bold;"';}?> href = " index.php?page=message&nbpage=<?php print $i; ?>" ><?php print $i ?></a>&nbsp;
				<?php
				$i++;
			}
			?> ]
		</span>
	</caption>

	<?php
	$id= 0;
		while ($message = mysql_fetch_array($word) )
		{
	?>
			<tr>
				<td><?php echo stripslashes($message['user']);?></td>
				<td class="messagecolor<?php print $id%2; ?>" rowspan="2"><?php echo stripslashes($message['message']); ?></td>
			</tr>
			<tr>
				<td><?php echo date( "G\hi d/m/y",$message['date']); ?></td>
			</tr>
	<?php
			$id++;	
		}
		mysql_query("UPDATE ".DATABASE_TABLE_USER." SET `last_message_read` = (SELECT max(id) FROM ".DATABASE_TABLE_MESSAGE.") WHERE `login` = '".$user->login."' LIMIT 1 ");
	?>
	</table>
</div>
<?php } ?>